/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cluelessserver;

import java.util.ArrayList;
import java.io.*;
import java.util.Iterator;

/**
 *
 * @author Dave
 */
class Player {
    Connection conn = null;    
    ArrayList<Card> hand = new ArrayList();
    BoardSpace location;
    String name;
    boolean hasLost = false;
    boolean hasMoved = false;
    boolean wasMoved = false;
    boolean isDoneMoving = false;
    boolean hasMadeSugg = false;
    boolean isHuman = false;
    
    void setLocation(BoardSpace space){
        if(!location.isRoom){
            location.isNotBlocked = true;
        }
        location = space;
        if (!space.isRoom){
            space.isNotBlocked = false;
        }
    }
    
    Player(){}
    Player(Connection c, String pName, Board gBoard){
        conn = c;
        conn.start();        
        name = pName;       
        location = gBoard.getRoom(pName+"Start");
        isHuman = true;
        
    }
    Player(String pName, Board gBoard){        
        name = pName;
        location = gBoard.getRoom(pName+"Start");
    }
    String handToString(){
        String hString = "";
        for (int i = 0; i < hand.size() - 1; i++){            
            hString += hand.get(i).toString() + " ";            
        }
        hString += hand.get(hand.size() - 1).toString();
        return hString;
    }
    
    void sendMessage(String type, String m) throws IOException{
        String message = type + " " + m;
        conn.out.println(message);        
    }
    String getMessage() throws IOException{
        while(conn.inLine == null){            
        }        
        return conn.inLine;        
    }
    boolean hasCard(String cardToFind){
        boolean cardFound = false;        
        Iterator it = hand.iterator();
        while(it.hasNext() && (!cardFound)){
            Card thisCard = (Card)it.next();
            if(thisCard.toString().equals(cardToFind))
            cardFound = true;            
        }
        return cardFound;
    }
    public String toString(){
        return name;
    }

    void addConnection(Connection connection) {
        conn = connection;
        isHuman = true;
    }
}
